package com.demo.bus_management.controller;

import com.demo.bus_management.entity.BusLine;
import com.demo.bus_management.service.BusLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@ResponseBody
@RestController
@RequestMapping("/buslines")
public class BusLineController {

    @Autowired
    private BusLineService busLineService;

    @GetMapping("/getAll")
    public List<BusLine> getAllBusLines() {
        return busLineService.getAllBusLines();
    }

    @GetMapping("getBusLineById/{id}")
    public BusLine getBusLineById(@PathVariable Long id) {
        return busLineService.getBusLineById(id);
    }

    @GetMapping("/getBusLineByname/{line_name}")
   public List<BusLine> getBusLineByName(@PathVariable String line_name) {
        return busLineService.getBusLineByName(line_name);
    }

    @GetMapping("/getBusLineBynumber/{line_number}")
    public List<BusLine> getBusLineByNumber(@PathVariable String line_number) {
        return busLineService.getBusLineByNumber(line_number);
    }
    @PostMapping("/addBusLine")
    public String addBusLine(@RequestBody BusLine busLine) {
        busLineService.addBusLine(busLine);
        return "增加路线成功";
    }



    @DeleteMapping("/deleteBusLine/{id}")
    public String deleteBusLine(@PathVariable Long id) {
        busLineService.deleteBusLine(id);
        return "删除路线成功";
    }
}

